import Vue from 'vue';
import iView from 'iview';

import {router} from './router/index';
import {appRouter} from './router/router';
import store from './store';
import App from './app.vue';
import '@/locale';
import VueI18n from 'vue-i18n';
import {get, post, del} from './libs/httpUtil';
import {hasPermissions} from './libs/permsUtil';
import './my-theme/index.less';

Vue.use(VueI18n);
Vue.use(iView);

Vue.prototype.$get = get;
Vue.prototype.$post = post;
Vue.prototype.$del = del;
Vue.prototype.$hasPerms = hasPermissions;

new Vue({
    el: '#app',
    router: router,
    store: store,
    render: h => h(App),
    data: {
        currentPageName: ''
    },
    mounted () {
        this.currentPageName = this.$route.name;
        // 显示打开的页面的列表
        this.$store.commit('setOpenedList');
        this.$store.commit('initCachepage');
        // 权限菜单过滤相关
        this.$store.commit('updateMenulist');
    },
    created () {
        let tagsList = [];
        appRouter.map((item) => {
            if (item.children.length <= 1) {
                tagsList.push(item.children[0]);
            } else {
                tagsList.push(...item.children);
            }
        });
        this.$store.commit('setTagsList', tagsList);
    }
});

// iView 相关的全局配置
// message 配置
iView.Message.config({
    top: 130,
    duration: 5
});
// notice 配置
iView.Notice.config({
    top: 130,
    duration: 8
});
// LoadingBar 配置
iView.LoadingBar.config({
    // color: '#5cb85c',
    // failedColor: '#f0ad4e',
    height: 3
});
